<?php
// No direct access
defined('_JEXEC') or die;

class JeneratorHelper
{
	/**
	 * Configure the Linkbar.
	 *
	 * @param	string	The name of the active view.
	 */
	public static function addSubmenu($vName = 'actions')
	{
		JSubMenuHelper::addEntry(
				JText::_('COM_JENERATOR_SUBMENU_ARTICLES'),
				'index.php?option=com_jenerator&view=actions',
				$vName == 'articles'
		);
		JSubMenuHelper::addEntry(
				JText::_('COM_JENERATOR_SUBMENU_CATEGORIES'),
				'index.php?option=com_categories&extension=com_jenerator',
				$vName == 'categories'
		);
		if ($vName=='categories') {
			JToolBarHelper::title(
					JText::sprintf('COM_CATEGORIES_CATEGORIES_TITLE',JText::_('com_jenerator')),
					'jenerator-categories');
		}
	}

	/**
	 * Gets a list of the actions that can be performed.
	 *
	 * @param	int		The category ID.
	 * @return	JObject
	 */
	public static function getActions($categoryId = 0)
	{
		$user	= JFactory::getUser();
		$result	= new JObject;

		if (empty($categoryId)) {
			$assetName = 'com_jenerator';
		} else {
			$assetName = 'com_jenerator.category.'.(int) $categoryId;
		}

		$actions = array(
				'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'
		);

		foreach ($actions as $action) {
			$result->set($action, $user->authorise($action, $assetName));
		}

		return $result;
	}
}
